﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BDSim
{
    public class DynamicUserDataProvider : BDSimDataProvider
    {
        DynamicUser _Parent;

        public DynamicUser Parent
        {
            get { return _Parent; }
            set { _Parent = value; }
        }

        #region 命令定义
        MenuCommand DynamicSetCmd = new MenuCommand();
        MenuCommand ImportTrackDataCmd = new MenuCommand();
        MenuCommand ImportAttitudeDataCmd = new MenuCommand();
        MenuCommand DynamicParamSetCmd = new MenuCommand();

        MenuCommand AddRecCmd = new MenuCommand();

        MenuCommand TrackDataShowCmd = new MenuCommand();
        MenuCommand TrackDataGraphicCmd = new MenuCommand();
        MenuCommand TrackDataReportCmd = new MenuCommand();

        MenuCommand AttitudeDataShowCmd = new MenuCommand();
        MenuCommand AttitudeDataGraphicCmd = new MenuCommand();
        MenuCommand AttitudeDataReportCmd = new MenuCommand();

        MenuCommand DeleteCmd = new MenuCommand();
        #endregion 命令定义

        #region 命令定义初始化
        public override void DefineCommand()
        {
            AddRecCmd.Header = "新建接收机";
            AddRecCmd.DefineExcuteCommand(AddReceiver);
            MenuCommandList.Add(AddRecCmd);

            DynamicSetCmd.Header = "动态设置";
            MenuCommandList.Add(DynamicSetCmd);

            ImportTrackDataCmd.Header = "导入轨迹数据";
            ImportTrackDataCmd.DefineExcuteCommand(ImportTrackDataFunc_Execute, ImportTrackDataFunc_CanExecute);
            DynamicSetCmd.SubMenuCommandList.Add(ImportTrackDataCmd);

            ImportAttitudeDataCmd.Header = "导入姿态数据";
            ImportAttitudeDataCmd.DefineExcuteCommand(ImportAttitudeDataFunc, ImportAttitudeDataFunc_CanExecute);
            DynamicSetCmd.SubMenuCommandList.Add(ImportAttitudeDataCmd);

            TrackDataShowCmd.Header = "轨迹数据";
            MenuCommandList.Add(TrackDataShowCmd);

            TrackDataReportCmd.Header = "数据报告";
            TrackDataReportCmd.DefineExcuteCommand(TrackDataReport_Execute, TrackDataReport_CanExecute);
            TrackDataShowCmd.SubMenuCommandList.Add(TrackDataReportCmd);

            TrackDataGraphicCmd.Header = "数据图表";
            TrackDataGraphicCmd.DefineExcuteCommand(TrackDataGraphicFunc);
            TrackDataShowCmd.SubMenuCommandList.Add(TrackDataGraphicCmd);

            AttitudeDataShowCmd.Header = "姿态数据";
            MenuCommandList.Add(AttitudeDataShowCmd);

            AttitudeDataGraphicCmd.Header = "图形显示";
            AttitudeDataGraphicCmd.DefineExcuteCommand(AttitudeDataGraphicFunc);
            AttitudeDataShowCmd.SubMenuCommandList.Add(AttitudeDataGraphicCmd);

            AttitudeDataReportCmd.Header = "报表显示";
            AttitudeDataReportCmd.DefineExcuteCommand(AttitudeDataReportFunc);
            AttitudeDataShowCmd.SubMenuCommandList.Add(AttitudeDataReportCmd);

            DeleteCmd.Header = "删除";
            DeleteCmd.DefineExcuteCommand(DeleteDynamicUser);
            MenuCommandList.Add(DeleteCmd);
        }
        #endregion 命令定义初始化

        #region 命令实现方法

        #region 导入轨迹数据
        /// <summary>
        /// 导入轨迹执行方法
        /// </summary>
        /// <param name="param"></param>
        void ImportTrackDataFunc_Execute(object param)
        {
            LoadUserTrackView LoadUserTrackView = new LoadUserTrackView();
            LoadUserTrackView.DataContext = this.Parent;
            MainDispatcher.DlgAddLayoutDocument(LoadUserTrackView, this._Parent.Name + "_轨迹导入");
        }

        /// <summary>
        /// 导入轨迹功能命令可执行控制
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        bool ImportTrackDataFunc_CanExecute(object param)
        {
            bool flag = false;
            if (BDSimObject.GlobalStatus == ESimStatus.UnInited || BDSimObject.GlobalStatus == ESimStatus.End)
            {
                if (ETrackGenType.Import== Parent.TrackGenType)
                {
                    flag = true;
                }
            }
            return flag;
        }
        #endregion

        #region 导出轨迹数据执行方法
        /// <summary>
        /// 导出轨迹数据功能命令执行方法
        /// </summary>
        /// <param name="param"></param>
        void TrackDataReport_Execute(object param)
        {
            DataReportView dataPreview = new DataReportView();
            dataPreview.InitUserTrackData(Parent.UserTrajectory, Parent.Name);
            MainDispatcher.DlgAddLayoutDocument(dataPreview, Parent.Name + "_用户轨迹");
        }
        /// <summary>
        /// 导出轨迹数据能命令可执行控制
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        bool TrackDataReport_CanExecute(object param)
        {
            bool flag = false;
            if (BDSimObject.GlobalStatus != ESimStatus.Run && BDSimObject.GlobalStatus != ESimStatus.Initing)
            {
                flag = true;
            }
            return flag;
        }

        #endregion

        #region XXX执行方法
        /// <summary>
        /// XXX 功能命令执行方法
        /// </summary>
        /// <param name="param"></param>
        void XXX_Execute(object param)
        {

        }
        /// <summary>
        /// XXX功能命令可执行控制
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        bool XXX_CanExecute(object param)
        {
            bool flag = true;

            return flag;
        }

        #endregion

        void ImportAttitudeDataFunc(object param)
        {

        }
        bool ImportAttitudeDataFunc_CanExecute(object param)
        {
            bool flag = false;
            if (BDSimObject.GlobalStatus == ESimStatus.UnInited || BDSimObject.GlobalStatus == ESimStatus.End)
            {
                if (ETrackGenType.Import == Parent.TrackGenType)
                {
                    flag = true;
                }
            }
            return flag;
        }

        void AddReceiver(object param)
        {
            CReceiver Rec = new CReceiver();
            Rec.Name = "Receiver" + (this.Parent.RecCollection.Count() + 1).ToString();
            Rec.Id = this.Parent.RecCollection.Count() + 1;
            Rec.Parent = this.Parent;

            this.Parent.RecCollection.Add(Rec);
        }

        void TrackDataGraphicFunc(object param)
        {
        }
        void TrackDataReportFunc(object param)
        {

        }
        void AttitudeDataGraphicFunc(object param)
        {

        }
        void AttitudeDataReportFunc(object param)
        {

        }
        void DeleteDynamicUser(object param)
        {
            //删除飞机载体
            //Aircraft air;
            //for (int i = 0; i < Parent.Parent.UserModelList.Count(); i++)
            //{
            //    if (Uid == Parent.UserModelList[i].Uid)
            //    {
            //        air = (Aircraft)Parent.UserModelList[i];
            //        Parent.UserModelList.Remove(air);
            //    }
            //}
            Parent.Parent.UserModelList.Remove(this.Parent);
            //删除飞机载体上的接收机
            //RecCollection.Clear();
        }
        #endregion 命令实现方法
    }
}
